﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

public partial class admin_news_edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (null != Request.QueryString["s"])
            {
                this.ddlType.SelectedValue = Request.QueryString["s"].ToString();
                this.ddlType.Enabled = false;
            }
            if (null != Request.QueryString["id"])
            {
                CNews news = new CNews();
                DataRow r = news.ReadNews(Convert.ToInt32(Request.QueryString["id"].ToString()));
                if (null != r)
                {
                    this.tbTime.Text = r["datetime"].ToString();
                    this.tbTitle.Text = r["title"].ToString();
                    this.tbContent.Text = r["content"].ToString();
                }
                this.ddlType.Enabled = false;
            }
        }
        
    }

    protected void btnOk_Click(object sender, EventArgs e)
    {
        CNews news = new CNews();
        if (null != Request.QueryString["id"])
        {
            //更新
            news.Update(Convert.ToInt32(Request.QueryString["id"].ToString()), this.tbTitle.Text, this.tbContent.Text, this.tbTime.Text);
        }
        else
        {
            //添加
            news.Add(this.tbTitle.Text, Convert.ToInt32(this.ddlType.SelectedValue), this.tbTime.Text, this.tbContent.Text);
        }
        ScriptManager.RegisterClientScriptBlock(Page, upEdit.GetType(), "", "alert('操作完成!');", true);
    }

   protected void btnOk1_Click(object sender, EventArgs e)
    {
        //妈的，为什么要提交两次才能获取到内容，耽误时间啊，用户体验啊，Shit!!!
    }
}